package com.hnkywl.sts.service.taskdeal;

import com.hnkywl.sts.quartz.KhGdqcOrderTimeSyncJob;
import com.hnkywl.sts.service.sys.DsgdService;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;

/**
 * Created with IntelliJ IDEA.
 * User: nianjunyan
 * Date: 13-5-12
 * Time: 下午5:00
 * To change this template use File | Settings | File Templates.
 * 计划导入到保供系统
 */
@Service
@Transactional
public class DoGdImport {
    private KhGdqcOrderTimeSyncJob khGdqcOrderTimeSyncJob;
    private DsgdService dsgdService;

    public void handleTestJob(String nbgsIds, String hours, String minutes, String seconds) {
        try {
            //更改spring定时配置的cronExpression
            khGdqcOrderTimeSyncJob.updateNotificationInterval(hours, minutes, seconds);
            //先删除定时挂单DSGD表的数据
            dsgdService.deleteDsgdData();
            //再从新插入新的DSGD数据
            dsgdService.saveDsgdList(nbgsIds, hours, minutes, seconds);
        } catch (SchedulerException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ParseException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    @Autowired
    public void setKhGdqcOrderTimeSyncJob(KhGdqcOrderTimeSyncJob khGdqcOrderTimeSyncJob) {
        this.khGdqcOrderTimeSyncJob = khGdqcOrderTimeSyncJob;
    }

    @Autowired
    public void setDsgdService(DsgdService dsgdService) {
        this.dsgdService = dsgdService;
    }
}
